import { ObjectId } from "mongodb";
import { mongo } from "../mogoConfig";


const db = mongo.db("my_test")
db.collection("inventory")
    .bulkWrite([
        {
            insertOne: {
                document: {
                    "_id": ObjectId.createFromTime(new Date().getTime()),
                    item: "测试",
                    qty: 11
                }
            }
        },
        {
            updateMany: {
                filter: { qty: 12 },
                update: { $set: { item: "测试2" } },
                upsert: true
            }
        },
        {
            deleteOne: {
                filter: { qty: { $gte: 40 } }
            }
        }
    ])
    .then(result => {
        console.log(JSON.stringify(result, null, 2))
    }).catch(error => {
        console.log(error)
    }).finally(() => {
        mongo.close()
    })

console.log("执行结束")